import os

from gis.common.jsonlogger import JsonFormatter

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

SECRET_KEY = "n)-&0h&#yoy9w!36joykw#-hq12vg!63khct0*9c-4@_n@qu1o"

DEBUG = True

ALLOWED_HOSTS = ["*"]

INSTALLED_APPS = [
    "itpay.core.mch",
    "itpay.core.agency",
    "itpay.core.admin_ext",
    "itpay.core.recharge_order",
    "itpay.core.sys",
    "gis.admin.apps.AdminConfig",
    "gis.common.timer",
    "django.contrib.sessions",
    "test_without_migrations",
]

MIDDLEWARE = [
    "itpay.server_agency.base.middleware.TrackLoggerMiddleware",
    "gis.common.django_ext.middleware.ApiMiddleware",
]

ROOT_URLCONF = "itpay.server_agency.urls"

LANGUAGE_CODE = "zh-cn"

TIME_ZONE = "Asia/Chongqing"

USE_I18N = False

USE_L10N = False

USE_TZ = False

FIXTURE_DIRS = [BASE_DIR + "/tests/gis/admin/fixtures/"]

# session有效期20分钟
SESSION_COOKIE_AGE = 20 * 60

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "simple": {"format": "%(levelname)s %(asctime)s %(message)s"},
        "json_stat": {"()": JsonFormatter, "format": "%(message)s"},
    },
    "handlers": {
        "console": {"level": "DEBUG", "class": "logging.StreamHandler"},
        "file": {
            "level": "DEBUG",
            "class": "logging.FileHandler",
            "filename": "/var/log/itpay_new_agency/itpay_new_agency.log",
            "formatter": "simple",
        },
        "maestro_file": {
            "level": "INFO",
            "class": "logging.handlers.WatchedFileHandler",
            "filename": "/var/log/itpay_new_admin/maestro.json",
            "formatter": "json_stat",
        },
    },
    "root": {"level": "DEBUG", "handlers": ["console", "file"]},
    "loggers": {
        "django.db.backends": {
            "level": "INFO",
            "handlers": ["console"],
            "propagate": False,
        },
        "maestro": {"handlers": ["maestro_file"], "level": "INFO", "propagate": False},
    },
}

TASK_HANDLERS = ["itpay.core.recharge_order.order_service.TransOrderHandler"]

SAFE_DOG_CONFIG = {
    "api_domain": "103.230.241.52:8888",
    "app_key": "FBvRgOwY2JXwYnldPThgD2lljE5-NAFDUJk0blRC",
    "app_secret": "I5LVVpmMd9FcBOHOWyba42ZXvmZnoOTkdDzAVNG9",
    "use_https": False,
}

try:
    from itpay.conf.server import *  # noqa: F403 F401
except ImportError:
    print("ERROR: server conf load fail")

try:
    from .env_settings import *  # noqa: F403 F401
except ImportError:
    print("ERROR: env settings load fail")
